package com.ktjiaoyu.crm.controller;

import com.ktjiaoyu.crm.pojo.User;
import com.ktjiaoyu.crm.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Resource
    private UserService userService;

    //跳转到登陆页面
    @RequestMapping(value = "/login")
    public String toLogin(){
        return "login";
    }

    //进入登录页面
    @RequestMapping(value = "/toLogin")
    public String login(String usrName, String usrPassword, Model model, HttpSession session){
        User user=userService.login(usrName,usrPassword);
        if(user!=null){
            session.setAttribute("loginUser",user);
            return "main";
        }else{
            model.addAttribute("msg","用户名或密码错误，登录失败！");
            return "logins";
        }
    }
    //跳转到主页面
    @RequestMapping(value = "/main")
    public String main(){
        return "main";
    }


    //进入主页面
//    @RequestMapping(value = "/toMain")
//    public String mains(HttpServletRequest request,HttpSession session){
//        String name=request.getParameter("usrName");
//        String password=request.getParameter("usrPassword");
//        User user=new User(name,password);
//       session.setAttribute("loginUser",user);
//       return "redirect:/main";
//    }
}
